package com.frain.springcloud.listener.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.frain.springcloud.common.RequestHelper;
import com.frain.springcloud.listener.entity.MyEvent;
import com.frain.springcloud.listener.entity.MyOneEvent;
import com.frain.springcloud.listener.entity.MyTwoEvent;

@RestController
@RequestMapping("/listener")
public class ListenerController implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    @RequestMapping("/test")
    public void testMyEvent(String userName, String password) {
        applicationContext.publishEvent(new MyEvent("hello", userName, password));
    }

    @RequestMapping("/testOne")
    public void testMyOneEvent(String userName, String password) {
        applicationContext.publishEvent(new MyOneEvent("helloOne", userName, password));
    }

    @RequestMapping("/testTwo")
    public void testMyTwoEvent(String userName, String password) {
        applicationContext.publishEvent(new MyTwoEvent("helloTwo", userName, password));
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;

    }

    @RequestMapping("/testvalue")
    public void test(HttpServletRequest request) {

        Map<String, Object> map = RequestHelper.getParamMap(request);

        System.out.println(map);

    }

}
